﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
using Stimulsoft.Report;
using Portal.Web.Global;
using Portal.Web.Framework;
using Portal.AssetTn.Model;
using Portal.Core;


namespace Portal.Gui.Web.WebParts.AssetTn
{
    public class AssetTN_PrintCollect : WebPart
    {
        public override string WebPartId
        {
            get
            {
                return "AssetTN.PrintCollect";
            }
        }


        public override WebPartServiceCls WebPartService
        {
            get
            {
                return AssetUtility.WebPartService;
            }
        }

        public override string Title
        {
            get
            {
                return "In sổ sưu tầm hiện vật";
            }
        }

        public override string Description
        {
            get
            {
                return "";
            }
        }


        public override string RenderWebPart(LoadParamCls loadParamCls)
        {
            try
            {
                string SiteId = loadParamCls.SiteId;
                Environments.CheckSessionTimeOut(true);
                Permission.CheckPermission(
                     SiteId,
                     Environments.CurrentLoginUser.LoginName,
                     Portal.AssetTn.Security.Permission.GetPermissionId(),
                     Portal.AssetTn.Security.Permission.ePermisionType.Portal_AssetTn_Main.ToString(),
                     Portal.AssetTn.Security.Permission.eFunction.Portal_AssetTn_Report.ToString(),
                     Portal.AssetTn.Security.Permission.GetPermissionId(),
                     null,
                     true);

                bool VisibleSearchForm = true;
                string SessionId = (string)Environments.Request("SessionId");
                if (string.IsNullOrEmpty(SessionId))
                {
                    SessionId = System.Guid.NewGuid().ToString();
                }
                else
                {
                    VisibleSearchForm = false;
                }
                string Subject = loadParamCls.RefTitle;
                if (string.IsNullOrEmpty(Subject))
                {
                    Subject = Title;
                }
                
                string RetHtml = AssetRenderPrintBll.Render(SessionId, "print", WebPartId, SiteId, "sosuutamhienvat", "Điều kiện in sổ sưu tập hiện vật", "print_large.png", "so-suu-tam-hien-vat.mrt",false, VisibleSearchForm);
                return RetHtml;
            }
            catch (Exception ex)
            {
                return ex.Message.ToString();
            }
        }


        //[AjaxPro.AjaxMethod]
        //public AjaxReturn ServerSidePrint(string SiteId,string SessionId)
        //{
        //    AjaxReturn oAjaxReturn = new AjaxReturn();
        //    try
        //    {
        //        //doan nay tim kiem
        //        Environments.CheckSessionTimeOut(true);
        //        DataSet dsResult = null;
        //        AssetModel[] AssetModels = AssetBll.Search(SiteId, "sosuutamhienvat", null, "EntryDate", ref dsResult);
        //        if (AssetModels.Length == 0) throw new Exception("Không có dữ liệu để in sổ!");
        //        dsResult.Tables[0].TableName = "TableAssetList";
        //        dsResult.DataSetName = "TableAssetList";
        //        ReportServiceBll.SaveData(SiteId,Environments.CurrentLoginUser.LoginName, dsResult, SessionId);
        //        //oAjaxReturn.RetUrl = "PrintCollect.aspx?SessionId="+SessionId;
        //        oAjaxReturn.RetUrl = "Print.aspx?wpid=" + WebPartId + "&SessionId=" + SessionId;
        //    }
        //    catch (Exception ex)
        //    {
        //        oAjaxReturn.Error = true;
        //        oAjaxReturn.InfoMessage = ex.Message.ToString();
        //    }
        //    return oAjaxReturn;
        //}


        public override void RegAjaxPro(System.Web.UI.Page ActivePage)
        {
            AjaxPro.Utility.RegisterTypeForAjax(typeof(AssetTN_PrintCollect));
            AjaxPro.Utility.RegisterTypeForAjax(typeof(AssetRenderPrintBll));
        }
    }
}
